<%-- 
    Document   : CMS_coverImage
    Created on : Nov 28, 2013, 3:15:20 PM
    Author     : BibooChung
--%>

<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "java.util.*" import="cart.hibernate.movieInformation.*" import="cart.hibernate.coverImage.*" import="cart.*,java.net.*,java.text.*" %>
<jsp:useBean id = "movieInformationManager" scope= "request" class = "cart.hibernate.movieInformation.ManageMovieInformation" />
<jsp:useBean id = "coverImageManager" scope= "request" class = "cart.hibernate.coverImage.ManageCoverImage" />

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Manage Cover Image</h1>

        <!-- Table with integrated management -->
        <table border="0" style="border-color:black;margin-bottom:20px;">
                <tr>
                    <th>Cover Image ID</th>
                    <th>Cover Image Name</th>
                    <th>Image</th>
                    <th>Update?</th>
                    <th>Delete?</th>
                </tr>
                <%
                //    List movieList = movieInformationManager.getAllCoverImage();
               //     Iterator iterCoverImage = movieList.iterator();
                    List coverImageList = coverImageManager.getAllImage();
                    List movieList = movieInformationManager.getAllMovie();

                    Iterator iterCoverImage = coverImageList.iterator();
                    Iterator iterMovie = movieList.iterator();

                    while (iterCoverImage.hasNext())
                    {

                        CoverImage coverImage = (CoverImage) iterCoverImage.next();
                %>
                        <tr>
                        <table>
                            <form action="ManageCoverImageServlet" method="post">
                                <input type="hidden" name="coverImageId" value="<%= coverImage.getCoverImageId() %>"> 
                                <td>
                                    <%= coverImage.getCoverImageId()%>
                                </td>
                                <td>
                                    <input type="text" name="password" value="<%= coverImage.getImageName()%>" />
                                </td>
                                <td>
                                    <select name="movieInformationId">
                                        <%
                                            while (iterMovie.hasNext())
                                            {
                                                MovieInformation movie = (MovieInformation) iterMovie.next();
                                                                               
                                                if(movie.getMovieId() == coverImage.getMovie().getMovieId())
                                                    out.print("<option value='" + movie.getMovieId() + "' selected='selected'>" + movie.getMovieName() + "</option>");
                                                else
                                                    out.print("<option value='" + movie.getMovieId() + "'>" + movie.getMovieName()+ "</option>");
                                            }
                                            iterMovie = movieList.iterator();
                                        %>
                                    </select>
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="update">
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="delete">
                                </td>
                            </form>
                        </table>
                        </tr>
                <%        
                    }
                %>
                    <tr>
                    <table>
                        <form action="ManageCoverImageServlet" method="post">
                            <td>Enter new cover image : </td>
                            <td><input type="text" name="password" id="password"></td>
                            <td>
                                <select name="movieInformationId">
                                    <%
                                        while (iterMovie.hasNext())
                                        {
                                            MovieInformation movie = (MovieInformation) iterMovie.next();
                                  //          out.print("<input type='hidden' name='movieInformationId' value='" + movie.getMovieId() + "'>");
                                            out.print("<option value='" + movie.getMovieId() + "'>" + movie.getMovieName() + "</option>");
                                        }
                                        iterMovie = movieList.iterator();
                                    %>
                                </select>
                            </td>
                            <td><input type="submit" name="submit" value="add"></td>
                        </form>
                    </table>
                    </tr>
        </table>
    </body>
</html>